package com.turing.system.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.turing.system.entity.Customer;
import com.turing.system.feign.AuthService;
import com.turing.system.mapper.CustomerWithdrawalsMapper;
import com.turing.system.service.CustomerService;
import com.turing.system.mapper.CustomerMapper;
import org.springframework.stereotype.Service;
import result.Result;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * @author dell
 * @description 针对表【customer(客户表)】的数据库操作Service实现
 * @createDate 2023-05-08 20:25:06
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer>
        implements CustomerService {

    @Resource
    private AuthService authService;
    @Resource
    private CustomerWithdrawalsMapper customerWithdrawalsMapper;
    @Resource
    private HttpServletRequest request;
    Double sum;

    @Override
    public Result getCusTakeIn(String token1) {
        //获取token
        String token = request.getHeader("Authorization");
        String tokenHead = "Bearer ";
        token = token.substring(tokenHead.length());
        if (token.contains(tokenHead)) {
            token = token.substring(tokenHead.length());
        }
        if ("".equals(token)) {
            token = null;
        }
        System.out.println("token = " + token);
        String strData = authService.getUserInfoByToken(token).getData().toString();
        System.out.println("strData = " + strData);
        String userId = strData.substring(strData.lastIndexOf("=") + 1, strData.lastIndexOf("}"));
        sum = customerWithdrawalsMapper.selectSumByValue(userId);
        return Result.success(sum == null ? 0.00 : sum);
    }
}




